package com.example.cinema.bindingdata;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.databinding.BindingAdapter;
import androidx.databinding.ObservableField;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.example.cinema.R;

//视频数据类
public class VideoData {

    @BindingAdapter("videoimgurl")
    public static void setImgUrl(View view, String url) {
        if (url == null) {
            return;
        }
        RequestOptions options = new RequestOptions()
                .placeholder(R.mipmap.defaut_img)
                .error(R.mipmap.defaut_img)
                .fallback(R.mipmap.defaut_img);
        Glide.with(view).load(url)
                .apply(options)
                .into((ImageView) view);
    }


    @BindingAdapter("uptaglist")
    public static void UpTagList(View view, String tag) {
        String[] strlist = tag.split(",");
        LinearLayout linearLayout = (LinearLayout) view;
        linearLayout.removeAllViews();
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        params.leftMargin = 2;
        params.rightMargin = 2;
        params.bottomMargin = 5;
        for (int i = 0; i < strlist.length; i++) {
            TextView tv = new TextView(view.getContext());
            tv.setPadding(5, 3, 5, 3);
            tv.setText(strlist[i]);
            tv.setTextSize(10);
            tv.setTextColor(Color.parseColor("#D06D15D1"));
            tv.setBackgroundResource(R.drawable.video_tag_bag);
            tv.setLayoutParams(params);
            linearLayout.addView(tv);
        }
    }



    public ObservableField<String> videoimge = new ObservableField<>();//视频封面图
    public ObservableField<String> videoname = new ObservableField<>();//视频名称
    public ObservableField<String> videotype = new ObservableField<>();//视频分类
    public ObservableField<String> videourls = new ObservableField<>();//视频播放地址
    public ObservableField<String> videotime = new ObservableField<>();//视频时长
    public ObservableField<String> videotage = new ObservableField<>();//视频标签
    public ObservableField<String> videobrief= new ObservableField<>();//视频简介
    public ObservableField<String> videogif  = new ObservableField<>();//GIF图片
    public ObservableField<String> videouser = new ObservableField<>();//上传用户
    public ObservableField<String> videousid = new ObservableField<>();//用户ID
    public ObservableField<String> videopart = new ObservableField<>();//片段
    public ObservableField<String> videolove = new ObservableField<>();//点赞量
    public ObservableField<String> videosid  = new ObservableField<>();//视频ID
    public ObservableField<String> videouimg = new ObservableField<>();//用户IMG
    public ObservableField<String> videouptime= new ObservableField<>();//上传时间
    public ObservableField<String> videoshort= new ObservableField<>();//短片地址
    public ObservableField<String> videothum = new ObservableField<>();//内容图
}
